package org.dromara.comm.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.comm.domain.AsServiceChannels;
import org.dromara.comm.domain.AsServicePlatform;
import org.dromara.comm.domain.AsServicePlatformEchoDisplay;
import org.dromara.comm.mapper.AsServiceChannelsMapper;
import org.dromara.comm.mapper.AsServicePlatformEchoDisplayMapper;
import org.dromara.comm.mapper.AsServicePlatformMapper;
import org.dromara.comm.service.AsServiceChannelsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 办事通分类业务层
 *
 * @author: 郭伟明
 * @date: 2024-07-31 10:59
 **/
@Service
public class AsServiceChannelsServiceImpl extends ServiceImpl<AsServiceChannelsMapper, AsServiceChannels> implements AsServiceChannelsService {

    @Autowired
    private AsServiceChannelsMapper asServiceChannelsMapper;

    @Autowired
    private AsServicePlatformMapper asServicePlatformMapper;

    @Autowired
    private AsServicePlatformEchoDisplayMapper asServicePlatformEchoDisplayMapper;


    /**
     * 服务指南全部
     * @param asServiceChannels
     * @return
     */
    @Override
    public List<Map<String, Object>> serviceGuideAll(AsServiceChannels asServiceChannels) {
        List<Map<String, Object>> arrayList = new ArrayList<>();
        List<AsServiceChannels> serviceChannels = asServiceChannelsMapper.selectList(null);

        for (AsServiceChannels serviceChannel : serviceChannels) {
            LambdaQueryWrapper<AsServicePlatform> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(AsServicePlatform::getCategoryId, serviceChannel.getId());
            List<AsServicePlatform> asServicePlatforms = asServicePlatformMapper.selectList(wrapper);

            Map<String, Object> serviceChannelMap = new HashMap<>();
            serviceChannelMap.put("id", serviceChannel.getId());
            serviceChannelMap.put("isDelete", serviceChannel.getIsDelete());
            serviceChannelMap.put("categoryName", serviceChannel.getCategoryName());
            serviceChannelMap.put("asServicePlatforms", asServicePlatforms);

            Map<String, Object> result = new HashMap<>();
            result.put("serviceChannel", serviceChannelMap);

            arrayList.add(result);
        }

        return arrayList;
    }

    /**
     * 添加服务指南
     * @param asServiceChannels
     */
    @Override
    public void insertAsServiceChannels(AsServiceChannels asServiceChannels) {
        asServiceChannelsMapper.insert(asServiceChannels);
    }

    /**
     * 添加政务服务
     * @param asServicePlatformEchoDisplay
     */
    @Override
    public void insertAsServicePlatformEchoDisplay(AsServicePlatformEchoDisplay asServicePlatformEchoDisplay) {
        AsServicePlatformEchoDisplay platform = new AsServicePlatformEchoDisplay();
        platform.setCategoryId(asServicePlatformEchoDisplay.getCategoryId());
        platform.setClassName(asServicePlatformEchoDisplay.getClassName());
        platform.setDetailed(asServicePlatformEchoDisplay.getDetailed());
        asServicePlatformEchoDisplayMapper.insert(platform);
    }

    /**
     * 修改分类
     * @param asServicePlatformEchoDisplay
     */
    @Override
    public void updateAsServicePlatformEchoDisplay(AsServicePlatformEchoDisplay asServicePlatformEchoDisplay) {
        asServicePlatformEchoDisplayMapper.updateById(asServicePlatformEchoDisplay);
    }

    /**
     * 删除分类
     *
     * @param asServicePlatformEchoDisplay
     */
    @Override
    public void deleteAsServicePlatformEchoDisplay(AsServicePlatformEchoDisplay asServicePlatformEchoDisplay) {
        asServicePlatformEchoDisplayMapper.deleteById(asServicePlatformEchoDisplay.getId());
    }

    /**
     * 查询全部的服务指南信息
     * @param id
     * @return
     */
    @Override
    public AsServicePlatform queryServicePlatform(Integer id) {
        return asServicePlatformMapper.selectById(id);
    }


}
